
function setTab(m,n){
var tli=document.getElementById("mm"+m).getElementsByTagName("li");
var mli=document.getElementById("nn"+m).getElementsByTagName("ul");
for(i=0;i<tli.length;i++){
   tli[i].className=i==n?"hover":"";
   mli[i].style.display=i==n?"block":"none";
}
}
//图片切换
function DY_scroll(wraper,prev,next,img,speed,or)
{ 
	var pic_num = 0;
	var wraper = $(wraper);
	var prev = $(prev);
	var next = $(next);
	var img = $(img);
	var pic_count = img.find('li').length;
	var w = img.find('li').outerWidth(true);
	var s = speed;
	next.click(function(){
			pic_num = pic_num<pic_count ? ((pic_num+1)%pic_count) :0;
			img.animate({'margin-left':-w},function(){
				img.find('li').eq(0).appendTo(img);
				img.css({'margin-left':0});
				$('#banner_ico li.on').removeClass('on');
				$("#banner_ico li").eq(pic_num).addClass('on');
			});
	});
	prev.click(function(){
			pic_num = pic_num==0 ? pic_count-1 : pic_num-1;
			img.find('li:last').prependTo(img);
			img.css({'margin-left':-w});
			img.animate({'margin-left':0});
			$('#banner_ico li.on').removeClass('on');
			$("#banner_ico li").eq(pic_num).addClass('on');
	});
	$('#banner_ico li').click(function(){
		var tmp_num = $(this).index('#banner_ico li');
		var count = pic_num;
		if(tmp_num < count){
			for(var i = count; i > tmp_num; i--){
				prev.click();
			}
		} else{
			for(var i = tmp_num; i > count; i--){
				next.click();
			}
		}

	});

	if (or == true){
		ad = setInterval(function() { next.click();},s*1000);
		wraper.hover(function(){clearInterval(ad);},function(){ad = setInterval(function() { next.click();},s*1000);});
	}
}
// 首页9大块
var lazyLayout = function(elem, _option_){
    var elem = elem;
    var option = {
        grid_v : 8,
        item_w : 0,
        item_h : 0
    };
    $.extend(option, _option_);
    option.item_w = option.item_h = $(elem).width() / option.grid_v;
    
    var centerobj = null;

    var zoomconfig = [ {w: 495, h: 247, l: 248, t: 0},{w: 619, h: 247, l: 248, t: 0},{w: 411, h: 205, l: 206, t: 0},{w: 514, h: 205, l: 206, t: 0},{w: 412, h: 205, l: 0, t: 0}];
    var normalconfig = [
        [
            {w:123, h:123, l:0, t:0},{w:123, h:123, l:124, t:0},{w:123, h:123, l:744, t:0},{w:123, h:123, l:868, t:0},
            {w:123, h:123, l:0, t:124},{w:123, h:123, l:124, t:124},{w:123, h:123, l:744, t:124},{w:123, h:123, l:868, t:124}
        ],
        [
            {w:123, h:123, l:0, t:0},{w:123, h:123, l:124, t:0},{w:123, h:123, l:868, t:0},{w:123, h:123, l:992, t:0},
            {w:123, h:123, l:0, t:124},{w:123, h:123, l:124, t:124},{w:123, h:123, l:868, t:124},{w:123, h:123, l:992, t:124}
        ],
        [
            {w:102, h:102, l:0, t:0},{w:102, h:102, l:103, t:0},{w:102, h:102, l:618, t:0},{w:102, h:102, l:721, t:0},
            {w:102, h:102, l:0, t:103},{w:102, h:102, l:103, t:103},{w:102, h:102, l:618, t:103},{w:102, h:102, l:721, t:103}
        ],
        [
            {w:102, h:102, l:0, t:0},{w:102, h:102, l:103, t:0},{w:102, h:102, l:721, t:0},{w:102, h:102, l:824, t:0},
            {w:102, h:102, l:0, t:103},{w:102, h:102, l:103, t:103},{w:102, h:102, l:721, t:103},{w:102, h:102, l:824, t:103}
        ],
        [
            {w:102, h:102, l:0, t:206},{w:102, h:102, l:103, t:206},{w:102, h:102, l:206, t:206},{w:102, h:102, l:309, t:206},
            {w:102, h:102, l:0, t:309},{w:102, h:102, l:103, t:309},{w:102, h:102, l:206, t:309},{w:102, h:102, l:309, t:309}
        ]
    ];
    var ww = $(window).width();
    var curzoom;
    var curnormal;
    //var curzoom = ww>1680 ? zoomconfig[0] : zoomconfig[3];
    //var curnormal = ww> 1680 ? normalconfig[0] : normalconfig[3];
    if (ww >= 1800) {
        curzoom = zoomconfig[1];
        curnormal = normalconfig[1];
    } else if (ww > 1679 && ww < 1800 ) {
        curzoom = zoomconfig[0];
        curnormal = normalconfig[0];
    } else if (ww <= 1679 && ww > 1360 ) {
        curzoom = zoomconfig[3];
        curnormal = normalconfig[3];
    } else if (ww <= 1360 && ww >= 950 ) {
        curzoom = zoomconfig[2];
        curnormal = normalconfig[2];
    } else {
        curzoom = zoomconfig[4];
        curnormal = normalconfig[4];
    }

    
    var init = function(){
        var index = 0;
        $(".wrap_main_ul .griditem").each(function(){
            if($(this).hasClass("zoom")){
                centerobj = this;
                $(this).css({
                    left: curzoom.l,
                    top : curzoom.t,
                    width: curzoom.w,
                    height: curzoom.h
                });
            }else{
                $(this).find(".main_ul").hide();
                $(this).css({
                    left: curnormal[index].l,
                    top : curnormal[index].t,
                    width: curnormal[index].w,
                    height: curnormal[index].h
                });
                index++;
            }
        });
    }
    
    var zoom = function(){
        var pos = $(this).position();
        $(this).stop().animate({
            left: curzoom.l,
            top : curzoom.t,
            width: curzoom.w,
            height: curzoom.h
        },function(){
            $(this).find(".main_ul").fadeIn();
        }).addClass("zoom").removeClass("box1");
    }
    var narrow = function(pos){
        $(this).stop().animate({
            left: pos.left,
            top: pos.top,
            width: curnormal[0].w,
            height: curnormal[1].h
        },function(){
            $(this).find(".main_ul").hide();
            $(this).removeClass("zoom").addClass("box1");
        });
    }
    
    var change = function(obj){
        if($(obj).hasClass("zoom"))return;
        var pos = $(obj).position();
        //var oldObj = $(elem).find(".zoom");
        zoom.call(obj);
        narrow.call(centerobj, pos);
        centerobj = obj;
    }
    

    $(window).resize(function(){

    var ww = $(window).width();
    if (ww >= 1800) {
        curzoom = zoomconfig[1];
        curnormal = normalconfig[1];
    } else if (ww >= 1679 && ww < 1800 ) {
        curzoom = zoomconfig[0];
        curnormal = normalconfig[0];
    } else if (ww < 1679 && ww > 1360 ) {
        curzoom = zoomconfig[3];
        curnormal = normalconfig[3];
    } else if (ww <= 1360 && ww >= 950 ) {
        curzoom = zoomconfig[2];
        curnormal = normalconfig[2];
    } else {
        curzoom = zoomconfig[4];
        curnormal = normalconfig[4];
    }
    
        init();
    });

    $(".wrap_main_ul .griditem").click(function(){
        change(this);
    });

    init();
}

$(function(){
    lazy = new lazyLayout($('.wrap_main_ul'), {});
})


//菜单
$(window).scroll(function(){
    var wrapsub = document.getElementById("wrap_sub");
    if (wrapsub != undefined) {
        var t = document.getElementById("wrap_sub").getBoundingClientRect().top;
        if(t<0)$(".wrap_sub").addClass("wrap_fix");
        else $(".wrap_sub").removeClass("wrap_fix");
    }
});

//二级页面背景等比缩放
$(function(){
    var w = document.documentElement.clientWidth;
    if(w< 1000)w=1000;
    var lt = $(".list_top");
    var lh = lt.height();
    lt.find("ul img").css("width", w).load(function(){
        var h = $(this).height();
        if(h < lh){
            $(this).css("width",  w * lh / h);
        }
    });
    
    $(window).resize(function(){
        var w = document.documentElement.clientWidth;
        if(w< 1000)w=1000;
        var lt = $(".list_top");
        var lh = lt.height();
        lt.find("ul img").css("width",w).each(function(){
            var h = $(this).height();
            if(h < lh){
                $(this).css("width",  w * lh / h);
            }
        });

    });
})


